<%@page import="java.util.ArrayList"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="classes.Conexao"%>
<%@page import="java.util.Date"%>
<%@page buffer="500kb" autoFlush="false" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" import="java.sql.*"%>
<%
    request.setCharacterEncoding("UTF-8");
    String str = " ";
    String SQL = "SELECT nm_alimento, qt_alimento, ds_alimento_equivalencia, cd_alimento FROM \"Operacoes\".\"ALIMENTO\" ";
    if (request.getParameter("nm_alimento") != null && !request.getParameter("nm_alimento").toString().isEmpty()) {
        String nm_alimento = request.getParameter("nm_alimento");
        System.out.println(nm_alimento.toUpperCase());
        SQL += " WHERE UPPER(nm_alimento) LIKE '%" + nm_alimento.toUpperCase() + "%' ";
    }
    SQL += " ORDER BY nm_alimento ";
    if (request.getParameter("offset") != null && !request.getParameter("offset").toString().isEmpty()) {
        String offset = request.getParameter("offset");
        SQL += " OFFSET " + offset + " ";
    }
    SQL += "LIMIT 10 ";

    try {
        ArrayList<Object[]> array = Conexao.getQuery(SQL);
        for (Object[] reg : array) {
            str += "<tr><td class=\"product-name\">"+reg[0]+"</td><td class=\"product-name\">"+reg[1]+"</td><td class=\"product-name\">"+reg[2]+"</td>";
            if (session.getAttribute("ic_admin") != null && session.getAttribute("ic_admin").toString().equals("true")){
                str += "<td class=\"product-name\"> ";

            str +=  "<a class=\"btn btn-warning btn-xs\" href=\"cadastrar_alimento.jsp?edit="+reg[3]+" \" name=\"btnEditarCRT\"> <i><svg id=\"canvas-for-livicon-57\" height=\"16\" version=\"1.1\" width=\"16\" xmlns=\"http://www.w3.org/2000/svg\" style=\"overflow: hidden; position: relative; left: -0.100006px; top: 0.883301px;\"> "
                    + "<desc> … </desc><defs></defs>"
                    + "<path style=\"opacity: 0;\" fill=\"#ffffff\" stroke=\"none\" d=\"M36.495,5.671L34.205,6.571000000000001C34.205,6.571000000000001,33.299,7.331,32.951,7.1240000000000006C32.571,6.898000000000001,32.864,5.6240000000000006,32.864,5.6240000000000006L33.598,4.686000000000001L32,2.812L34.031,1.8739999999999999C34.031,1.8739999999999999,34.83,0.46899999999999986,35.025,0.46899999999999986C35.458,0.46899999999999986,37.185,1.8739999999999999,37.185,1.8739999999999999L36.193000000000005,0.7959999999999998L37.186,0L40.211,0.936C40.211,0.936,39.348,2.343,39.778999999999996,2.812S40.601,7.125,40.169999999999995,7.125C39.736,7.125,36.928,4.077999999999999,36.928,4.077999999999999L40.04,7.498999999999999L38.396,7.325999999999999L36.71,8.155L33.814,7.263999999999999L36.495,5.671Z\" opacity=\"0\" stroke-width=\"0\" transform=\"matrix(0.5,0,0,0.5,0,0)\"></path>"
                    + "<path fill=\"#ffffff\" stroke=\"none\" d=\"M24,20V24H8V8H20L24,4H7C5.343,4,4,5.343,4,7V25C4,26.656,5.343,28,7,28H25C26.656,28,28,26.656,28,25V16L24,20Z\" transform=\"matrix(0.5,0,0,0.5,0,0)\" stroke-width=\"0\"></path>"
                    + "<path fill=\"#ffffff\" stroke=\"none\" d=\"M27.105,5.369L29.651,7.914999999999999C30.114,8.380999999999998,30.118,9.143999999999998,29.651,9.610999999999999L27.671,11.591L23.429,7.347999999999999L25.409,5.3679999999999986C25.877,4.9,26.637,4.9,27.105,5.369ZM12.817,20.788C12.817,20.788,12.817,17.959,15.646,15.131L22.722,8.055L26.964000000000002,12.298L19.888,19.373C17.060000000000002,22.201,14.232000000000003,22.202,14.232000000000003,22.202S12.524000000000003,23.322000000000003,12.111000000000002,22.908C11.668,22.468,12.817,20.788,12.817,20.788ZM17.202,18.1L23.57,11.733L22.72,10.884L16.351999999999997,17.252000000000002L17.202,18.1Z\" stroke-width=\"0\" transform=\"matrix(0.5,0,0,0.5,0,0)\"></path>"
                    + "</svg></i></a>&nbsp;";
            str +=  "<a class=\"btn btn-warning btn-xs\" value=\""+reg[3]+"\" name=\"btnExcluirCRT\" onclick=\"excluirAlimento("+reg[3]+");\"><i><svg id=\"canvas-for-livicon-57\" height=\"16\" version=\"1.1\" width=\"16\" xmlns=\"http://www.w3.org/2000/svg\" style=\"overflow: hidden; position: relative; left: -0.100006px; top: 0.883301px;\"> "
                    + "<desc> … </desc><defs></defs>"
                    + "<path style=\"opacity: 0;\" fill=\"#ffffff\" stroke=\"none\" d=\"M36.495,5.671L34.205,6.571000000000001C34.205,6.571000000000001,33.299,7.331,32.951,7.1240000000000006C32.571,6.898000000000001,32.864,5.6240000000000006,32.864,5.6240000000000006L33.598,4.686000000000001L32,2.812L34.031,1.8739999999999999C34.031,1.8739999999999999,34.83,0.46899999999999986,35.025,0.46899999999999986C35.458,0.46899999999999986,37.185,1.8739999999999999,37.185,1.8739999999999999L36.193000000000005,0.7959999999999998L37.186,0L40.211,0.936C40.211,0.936,39.348,2.343,39.778999999999996,2.812S40.601,7.125,40.169999999999995,7.125C39.736,7.125,36.928,4.077999999999999,36.928,4.077999999999999L40.04,7.498999999999999L38.396,7.325999999999999L36.71,8.155L33.814,7.263999999999999L36.495,5.671Z\" opacity=\"0\" stroke-width=\"0\" transform=\"matrix(0.5,0,0,0.5,0,0)\"></path>"
                    + "<path fill=\"#ffffff\" stroke=\"none\" d=\"M24.801,8.1H20V4.7C20,4.369,19.73,4.1000000000000005,19.4,4.1000000000000005H10.6C10.269,4.1000000000000005,10,4.369000000000001,10,4.7V8.1H5.2C4.537,8.1,4,8.637,4,9.3V11H26V9.3C26,8.637,25.463,8.1,24.801,8.1ZM12,8.1V6.1H18V8.1H12Z\" transform=\"matrix(0.5,0,0,0.5,0,0)\" stroke-width=\"0\"></path>"
                    + "<path fill=\"#ffffff\" stroke=\"none\" d=\"M8.4,30H21.6C22.926000000000002,30,24,28.926,24,27.6V12H6V27.6C6,28.926,7.075,30,8.4,30ZM10,26H8V14H10V26ZM14,26H12V14H14V26ZM18,26H16V14H18V26ZM22,26H20V14H22V26Z\" stroke-width=\"0\" transform=\"matrix(0.5,0,0,0.5,0,0)\"></path>"
                    + "</svg></i></a></td></tr>";
            }
            str += "$";
            str += array.size() + "$";
        }
        str = str.substring(0, str.length() - 1);
        out.println(str);
    } catch (Exception ex1) {
        ex1.printStackTrace();
    }


%>